//
//  FeedBase.m
//  SDDataTest
//
//  Created by sodao on 12-9-19.
//  Copyright (c) 2012年 sodao. All rights reserved.
//

#import "FeedBase.h"

static SBJsonParser* parser;
static SBJsonWriter* writer;
@implementation FeedBase
@synthesize feedID;
@synthesize lastUpdateDate;
-(id)init{
    self = [super init];
    if (!!self) {
        if(!parser)parser = [[SBJsonParser alloc] init];
        if(!writer)writer = [[SBJsonWriter alloc] init];
        self.lastUpdateDate = [NSDate date];
    }
    return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder{
    [aCoder encodeObject:self.lastUpdateDate forKey:kEncode_LastUpdateDate];
}
- (id)initWithCoder:(NSCoder *)decoder {
    if (self = [self init]) {
        self.lastUpdateDate = [decoder decodeObjectForKey:kEncode_LastUpdateDate];
    }
    return self;
}
-(void)dealloc{
    [super dealloc];
    [self.lastUpdateDate release];
}
-(NSDate*)getServerUTC:(long long)seconds{
    NSTimeZone* zone = [NSTimeZone timeZoneWithName:SDServerTimeZone];
    NSTimeInterval lv = seconds/1000;
    NSDate* newDate = [NSDate dateWithTimeIntervalSince1970:lv];
    NSTimeInterval times = [zone secondsFromGMTForDate:newDate];
    NSDate* date = [newDate addTimeInterval:times];
    return date;
}
-(NSDate*)getServerGMT:(long long)seconds{
    return nil;
}
-(NSString*)getFeedIDByObject:(id)obj{
    if ([obj isKindOfClass:[NSString class]]) {
        return obj;
    }else if([obj isKindOfClass:[NSNumber class]]){
        return [NSString stringWithFormat:@"%d",[(NSNumber*)obj intValue]];
    }
    return nil;
}
-(NSString*)changeNetDataToString:(NSData*)data{
    NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingUTF8);
    NSString* resstring = [[NSString alloc] initWithData:data encoding:enc];
    return resstring;
}
-(NSDictionary*)parserString:(NSString*)string{
    return [parser objectWithString:string];
}
-(NSString*)wiriteDicitionaryToString:(NSDictionary*)obj{
    return [writer stringWithObject:obj];
}
-(id)initWithData:(NSData*)data{
    return [self initWithString:[self changeNetDataToString:data]];
}
-(id)initWithString:(NSString*)string{
    return [self initwithDictionary:[self parserString:string]];
}
-(id)initWithDictionary:(NSDictionary*)dictionary{
    if (self = [self init]) {
        
    }
    return self;
}
+(id)getFeedByDictionary:(NSDictionary*)dictionary{
    return nil;
}
-(BOOL)isEqual:(id)object{
    if ([object isKindOfClass:[self class]]) {
        if (self == object||[self.feedID compare:((FeedBase*)object).feedID]==NSOrderedSame) {
            return YES;
        }
    }
    return NO;
}
@end
